<template>
	<div>
		<h1>销售信息查询：<span>排序方式：
		<select v-model="typeSort">
			<option value="0">销售日期</option>
			<option value="1">单笔总价</option>
		</select></span><button @click="getSaleInfo(currentNo)">提交</button></h1>
		<h1 v-show="dataList=='' || dataList.length==0">没有销售记录</h1>
		<div>
			<table cellpadding="2" cellspacing="2" border="1px">
				<tr>
					<td>ID</td>
					<td>商品</td>
					<td>单价</td>
					<td>数量</td>
					<td>总价</td>
					<td>销售日期</td>
					<td>销售人</td>
				</tr>
				<tbody>
					<tr v-for="item in dataList">
						<td>{{item.id}}</td>
						<td>{{item.productName}}</td>
						<td>{{item.price}}</td>
						<td>{{item.quantity}}</td>
						<td>{{item.totalPrice}}</td>
						<td>{{item.saleDate}}</td>
						<td>{{item.userName}}</td>		
					</tr>
				</tbody>
			</table>
			<p>
			<span @click="getSaleInfo(1)">首页|</span>
			<span @click="getSaleInfo(currentNo-1)">上一页|</span>
			<span @click="getSaleInfo(currentNo+1)">下一页|</span>
			<span @click="getSaleInfo(lastPage)">未页</span>
			<span>第{{currentNo}}页/共{{lastPage}}页({{totalCount}}条记录)</span>
			
			
			
			</p>
			
		</div>
	</div>
</template>

<script>
	import axios from 'axios'
	export default{
		data(){
			return{
				typeSort:"0",
				dataList:[],
				currentNo:1,
				lastPage:"",
				totalCount:""
			}
		},
		beforeCreate() {
			var that=this;
			var url="http://localhost:8080/getSaleInfo";
			axios.get(url,{
				params:{
					currentNo:1,
					typeSort:that.typeSort
				}
			}).then(res=>{
				console.log(res);
				if(res.data.message=="OK"){
					that.dataList=res.data.data.saleList;
					that.currentNo=res.data.data.currentPageNo;
					that.lastPage=res.data.data.totalPageCount;
					that.totalCount=res.data.data.totalCount;
				}
			})
		},
		methods:{
			getSaleInfo:function(currentNo){
				var that=this;
				var url="http://localhost:8080/getSaleInfo";
				axios.get(url,{
					params:{
						currentNo:currentNo,
						typeSort:that.typeSort
					}
				}).then(res=>{
					console.log(res);
					if(res.data.message=="OK"){
						that.dataList=res.data.data.saleList;
						that.currentNo=res.data.data.currentPageNo;
						that.lastPage=res.data.data.totalPageCount;
						that.totalCount=res.data.data.totalCount;
					}
				})
			}
		}
	}
</script>

<style>
</style>
